package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderMapper {

    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into orders" +
            "(number, status, user_id, address_book_id, order_time, checkout_time, pay_method, pay_status, amount, remark," +
            "phone, address, consignee, estimated_delivery_time, delivery_status, pack_amount, tableware_number,tableware_status)" +
            "values (#{number}, #{status}, #{userId}, #{addressBookId}, #{orderTime}, #{checkoutTime}, #{payMethod}," +
            "#{payStatus}, #{amount}, #{remark}, #{phone}, #{address}, #{consignee}," +
            "#{estimatedDeliveryTime}, #{deliveryStatus}, #{packAmount}, #{tablewareNumber}, #{tablewareStatus})")
    void submitOrder(Orders orders);

    /**
     * 批量新增setmeal_dish表
     * @param orderDetails
     */
    void insertBatch(List<OrderDetail> orderDetails);

    /**
     * 根据订单号和用户id查询订单
     * @param orderNumber
     * @param userId
     */
    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    /**
     * 历史订单查询接口
     */
    Page<OrderVO> queryByPage(OrdersPageQueryDTO pageQueryDTO);

    /**
     * 查询订单详情
     */
    OrderVO queryOrderDetail(Long id);

    /**
     * 取消订单
     */
    void cancelOrder(Orders orders);

    /**
     * 各个状态的订单数量统计
     */
    OrderStatisticsVO countOrderByStatus();

    /**
     * 根据id查询Orders
     * @param id
     * @return
     */
    @Select("select * from orders where id=#{id}")
    Orders getById(Long id);
}
